.TH std::istream_iterator::istream_iterator 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::istream_iterator::istream_iterator \- std::istream_iterator::istream_iterator

.SH Synopsis
   istream_iterator();                                      \fI(until C++11)\fP
   constexpr istream_iterator();                            \fI(since C++11)\fP
   constexpr istream_iterator(                          \fB(2)\fP \fI(since C++20)\fP
   std::default_sentinel_t );
   istream_iterator( istream_type& stream );        \fB(1)\fP \fB(3)\fP
   istream_iterator( const istream_iterator& other                        \fI(until C++11)\fP
   );                                                   \fB(4)\fP
   istream_iterator( const istream_iterator& other                        \fI(since C++11)\fP
   ) = default;

   1,2) Constructs the end-of-stream iterator
   , value-initializes the stored value. This constructor is constexpr if the
   initializer in the definition auto x = T(); is a constant initializer
   \fI(since C++11)\fP.
   3) Initializes the iterator, stores the address of stream in a data member, and
   performs the first read from the input stream to initialize the cached value data
   member.
   4) Constructs a copy of other.
   If std::is_trivially_copy_constructible<T>::value is true, this copy constructor is
   a trivial copy constructor.
   \fI(since C++11)\fP

.SH Parameters

   stream - stream to initialize the istream_iterator with
   other  - another istream_iterator of the same type

.SH Example


// Run this code

 #include <algorithm>
 #include <iostream>
 #include <iterator>
 #include <sstream>

 int main()
 {
     std::istringstream stream("1 2 3 4 5");
     std::copy(
         std::istream_iterator<int>(stream),
         std::istream_iterator<int>(),
         std::ostream_iterator<int>(std::cout, " ")
     );
 }

.SH Output:

 1 2 3 4 5

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

      DR    Applied to        Behavior as published              Correct behavior
   LWG 1280 C++98      overload \fB(3)\fP stored stream directly  stores its address instead
   P0738R2  C++98      the first read might be deferred to  always performed in the
                       the first dereference                constructor
